/*
package com.gyms.fragment;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.classic.okhttp.beans.HVCitiesBean;
import com.classic.okhttp.beans.HVProjectBean;
import com.classic.okhttp.beans.HVSubCitiesBean;
import com.classic.okhttp.beans.HVVenueBean;
import com.classic.okhttp.enums.Enum;
import com.classic.okhttp.services.IVenueService;
import com.classic.okhttp.zmoumall.http.ObjectCallback;
import com.classic.okhttp.zmoumall.utils.ToastUtil;
import com.gyms.MyApplication;
import com.gyms.R;
import com.gyms.activity.GymDetailActivity;
import com.gyms.activity.GymsActivity;
import com.gyms.adapter.GymsRecyclertAdapter;
import com.gyms.base.BaseFragment;
import com.gyms.bean.ThreeWheelBean;
import com.gyms.constant.Constants;
import com.gyms.manager.LocationManger;
import com.gyms.manager.StatisticsManager;
import com.gyms.view.wheel.SingleWheelDialog;
import com.gyms.view.wheel.ThreeWheelTimeDialog;
import com.gyms.view.wheel.WheelDialog;
import com.orhanobut.logger.Logger;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import cn.bingoogolapple.refreshlayout.pulltoxrecycleview.XRecyclerView;
import constant.EventConstant;
import myInterface.OnItemClickLitener;
import utils.EmptyUtils;
import weight.CommonEmptyView;
import weight.UiEvent;

*/
/**
 * 找场馆列表
 *//*

public class GymsListFragment extends BaseFragment implements View.OnClickListener , CommonEmptyView.UpdateClick{
    @BindView(R.id.category)
    LinearLayout category;
    @BindView(R.id.time_quantum)
    LinearLayout timeQuantum;
    @BindView(R.id.area)
    LinearLayout area;
    @BindView(R.id.bg_refresh_layout)
    XRecyclerView bgRefreshLayout;
    @BindView(R.id.tv_gyms_category)
    TextView tvGymsCategory;
    @BindView(R.id.tv_gyms_time)
    TextView tvGymsTime;
    @BindView(R.id.tv_gyms_area)
    TextView tvGymsArea;


    private String projectName, gymsTime = "今天(06:00－22:00)", keyword = null;
    private int startTime, endTime;
    Handler handler = new Handler();
    private int mPageIndex = 1;
    private int mIsRefreshOrLoadMore = 0;//0是刷新1是加载更多


    private List<HVVenueBean> mHVVenueBean = new ArrayList<>();//场馆列表数据源

    private GymsRecyclertAdapter mAdapter;

    private int lastClickTag = 0;

    private final int PROJECT = 2031;
    private final int DATE = 2032;
    private final int AREA = 2033;
    private String projectId, areaCode;
    private final static int PAGESIZE = 10;
    private ThreeWheelBean wheelBean;
    //    private boolean isPeriod = false;
    @BindView(R.id.search_empty)
    CommonEmptyView searchEmpty;
    private GymsActivity mActivity;
    private LocationManger mLocationManger;//定位的manger

    private String mProjectStr="";//显示的运动分类
    private String mAreaStr="";//显示区域分类

    private List<HVProjectBean> hVProjectBean;//运动分类bean
    private HVCitiesBean citiesBean;//城市的bean
    private ArrayList<String> mProjectList=new ArrayList<>();
    private ArrayList<HVSubCitiesBean> mAreasList;
    private  ArrayList<String> mAreaStrLists = new ArrayList<>();


    @Override
    protected int getLayoutResId() {
        return R.layout.activity_gyms_list;
    }

    @Override
    public void onRefresh() {
        Bundle bundle = getArguments();//从activity传过来的Bundle
        projectId = bundle.getString(Constants.FLAG_INTENT_PROJECTID);
//        isPeriod = bundle.getBoolean(Constants.FLAG_INTENT_ISPERIOD, false);
        projectName = EmptyUtils.isNotEmpty(bundle.getString(Constants.FLAG_INTENT_PROJECTNAME)) ? bundle.getString(Constants.FLAG_INTENT_PROJECTNAME) : "羽毛球";
        wheelBean = (ThreeWheelBean) bundle.getSerializable("wheelBean");
        if (wheelBean != null) {
            startTime = wheelBean.getStartTimeInt();
            endTime = wheelBean.getEndTimeLInt();
            gymsTime = wheelBean.getDateStr().substring(0, 2) + "(" + wheelBean.getStartTimeStr() + "-" + wheelBean.getEndTimeStr() + ")";
        }
        tvGymsCategory.setText(projectName);
        tvGymsTime.setText(gymsTime);
        mLocationManger = LocationManger.getInstance(getActivity());
        areaCode = mLocationManger.getCityCode();
    }


    @Override
    protected void initView() {
        createLoadingView("加载中", true);
        searchEmpty.setUpDateClick(this);
        mActivity=(GymsActivity)getActivity();
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        bgRefreshLayout.setLayoutManager(layoutManager);
        mAdapter = new GymsRecyclertAdapter(mContext, mHVVenueBean);
        bgRefreshLayout.setAdapter(mAdapter);

        initProjectList();
        initAreaList();
        //这句就是添加我们自定义的分隔线
//        if (!isPeriod) {
//            timeQuantum.setVisibility(View.GONE);
//        } else {
//            timeQuantum.setVisibility(View.VISIBLE);
//        }

    }

    */
/**
     * 初始化地区列表
     *//*


    private void initAreaList() {
     citiesBean = ((MyApplication) getActivity().getApplication()).mHVCitiesBean;
        if (citiesBean != null) {
            mAreasList = citiesBean.getAreas();
        }

        mAreaStrLists.add("全部区域");
        if (mAreasList == null) {
            return;
        }
        for (HVSubCitiesBean area : mAreasList) {
            mAreaStrLists.add(area.getName());
        }
    }

    */
/**
     * 初始化运动分类列表
     *//*


    private void initProjectList() {
        hVProjectBean = ((MyApplication) getActivity().getApplication()).mHVProjectBean;
        mProjectList.add(Constants.ALL_SPORT_STR);
        if (hVProjectBean == null) {
            return;
        }
        for (HVProjectBean bean : hVProjectBean) {
            mProjectList.add(bean.getProjectName());
        }
    }

    @Override
    protected void initListener() {
//        bgRefreshLayout.setDelegate(this);
        category.setOnClickListener(this);
        timeQuantum.setOnClickListener(this);
        area.setOnClickListener(this);
        EventBus.getDefault().register(this);

//        BGARefreshViewHolder refreshViewHolder = new BGANormalRefreshViewHolder(mContext, true);
//        // 设置下拉刷新和上拉加载更多的风格
//        bgRefreshLayout.setRefreshViewHolder(refreshViewHolder);

//        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                Bundle mBundle = new Bundle();
//                mBundle.putString(Constants.FLAG_INTENT_VENUEID, mHVVenueBean.get(position).getVenueId());
//                startActivity(GymDetailActivity.class, mBundle, false);
//            }
//        });
        bgRefreshLayout.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                //刷新的时候将pageIndex始终为1
                mPageIndex = 1;
                mIsRefreshOrLoadMore = 0;
                bgRefreshLayout.setLoadingMoreEnabled(true);
                getVenueList();
            }

            @Override
            public void onLoadMore() {
                mPageIndex++;
                mIsRefreshOrLoadMore = 1;
                getVenueList();
            }
        });
        mAdapter.setOnItemClickLitener(new OnItemClickLitener() {
            @Override
            public void onItemClick(View view, int position) {
                Bundle mBundle = new Bundle();
                mBundle.putString(Constants.FLAG_INTENT_VENUEID, mHVVenueBean.get(position).getVenueId());
                startActivity(GymDetailActivity.class, mBundle, false);
            }
        });
    }

    @Override
    protected void processLogic() {
        getVenueList();
    }


    */
/**
     * 获取场馆列表
     *//*

    private void getVenueList() {
        if (null != loadingView) {
            loadingView.show();
        }
        IVenueService.getVenueList(getActivity(), areaCode, mLocationManger.longitude, mLocationManger.latitude, projectId, startTime, endTime, "", mPageIndex, PAGESIZE, Enum.EnumVenueListType.Field,null, true,
                new ObjectCallback<ArrayList<HVVenueBean>>() {
                    @Override
                    public void onSuccess(ArrayList<HVVenueBean> response, String message) {
                        dialogDis();
                        Logger.e("getVenueList=Gym=onSuccess"+message);
                        mActivity.dialogDis(bgRefreshLayout,searchEmpty);
                        if (mIsRefreshOrLoadMore == 1) {
                            bgRefreshLayout.loadMoreComplete();
                        } else if (mIsRefreshOrLoadMore == 0) {
                            bgRefreshLayout.refreshComplete();
                        }
                        if (null != response && response.size() != 0) {
                            if (mIsRefreshOrLoadMore == 0) {//刷新清空数据源
                                mHVVenueBean.clear();
                            }
                            mAdapter.setData(response);
                        } else {
                            if (mIsRefreshOrLoadMore == 0) {
                                showEmptyView(bgRefreshLayout,searchEmpty, 1);
                            } else {
                                doLoadMoreErro("没有更多的数据了");
                            }
                        }
                    }

                    @Override
                    public void onErrorT(int code, ArrayList<HVVenueBean> response, String errorMessage) {
                        dialogDis();
                        Logger.e("getVenueList=Gym=onErrorT"+errorMessage);
                        showEmptyView(bgRefreshLayout,searchEmpty, code);
                    }

                    @Override
                    public void onHttpErrorCall(int statusCode) {
                        dialogDis();
                        Logger.e("getVenueList=Gym=onHttpErrorCall"+statusCode);
                        showEmptyView(bgRefreshLayout,searchEmpty, Constants.NO_NET);
                    }
                });
    }


    private void hideSoftInput() {
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        View currentFocus = getActivity().getCurrentFocus();
        if (null != currentFocus) {
            imm.hideSoftInputFromWindow(currentFocus.getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

    */
/**
     * 加载更多出现错误的处理
     *//*

    private void doLoadMoreErro(String erroStr) {
        if (mIsRefreshOrLoadMore == 1) {
            mPageIndex--;
            if(bgRefreshLayout!=null) {
                bgRefreshLayout.setNoMoreData();
            }
            ToastUtil.showToast(mContext, erroStr);
        } else if (mIsRefreshOrLoadMore == 0) {
            if(bgRefreshLayout!=null) {
                bgRefreshLayout.refreshComplete();
            }
        }
    }


   */
/* @Override
    public void onBGARefreshLayoutBeginRefreshing(BGARefreshLayout refreshLayout) {
        //刷新的时候将pageIndex始终为1
        mPageIndex = 1;
        mIsRefreshOrLoadMore = 0;
        getVenueList();
    }

    @Override
    public boolean onBGARefreshLayoutBeginLoadingMore(BGARefreshLayout refreshLayout) {
        mPageIndex++;
        mIsRefreshOrLoadMore = 1;
        getVenueList();
        return true;
    }*//*


    @Override
    public void onClick(View v) {
        hideSoftInput();

        switch (v.getId()) {
            case R.id.category://运动分类

                SingleWheelDialog singleWheelDialog = new SingleWheelDialog(getActivity(), R.style.BottomToTopAnim);
                singleWheelDialog.setData(projectName, mProjectList);
                //运动项目
                singleWheelDialog.setOnClickSubmitListener(new WheelDialog.OnClickSubmitListener() {
                    @Override
                    public void onClickSubmit(String[] values, ThreeWheelBean threeWheelBean) {

                        if (values != null && values.length == 1) {
                            String mTempProjectName=values[0];
                           */
/* if (mTempProjectName.equals(Constants.ALL_SPORT_STR)){//全部
                                projectId=null;
                                mProjectStr=Constants.ALL_SPORT;
//                                tvGymsCategory.setText("所有运动");
                                projectName=Constants.ALL_SPORT_STR;
                            }else {
//                                tvGymsCategory.setText(values[0]);
                                projectName=mTempProjectName;
                                mProjectStr=mTempProjectName;
                            }*//*

                          */
/*  for (HVProjectBean bean : hVProjectBean) {
                                if (mTempProjectName.equals(bean.getProjectName())) {
                                    projectId = bean.getProjectId();
                                }
                            }*//*

                            //刷新的时候将pageIndex始终为1
//                            getProjectId(mTempProjectName);//比如选全部  需要显示所有运动
                            EventBus.getDefault().post(new UiEvent(EventConstant.FLAG_SEARCH_PROJECT,mTempProjectName));

                            HashMap<String, String> map = new HashMap<>();
                            map.put("project", projectId);
                            StatisticsManager.onEvent(mContext, StatisticsManager.VenueList_Sports, map);

                           */
/* mPageIndex = 1;
                            mIsRefreshOrLoadMore = 0;
                            getVenueList();*//*

//                           refreshData();
                        }
                    }

                    @Override
                    public void onNotTimeSelect() {

                    }
                });
                singleWheelDialog.show();
                break;

            case R.id.time_quantum://时间分类

                StatisticsManager.onEvent(mContext, StatisticsManager.VenueList_TimeSelect);

                lastClickTag = DATE;
                final ThreeWheelTimeDialog mChooseTimeShortDialog = new ThreeWheelTimeDialog(getActivity(), R.style.BottomToTopAnim);
                mChooseTimeShortDialog.setDate();
                //时间筛选
                mChooseTimeShortDialog.setOnClickSubmitListener(new WheelDialog.OnClickSubmitListener() {
                    @Override
                    public void onClickSubmit(String[] values, ThreeWheelBean threeWheelBean) {
                        tvGymsTime.setText(threeWheelBean.getDateStr().substring(0, 2) + "(" + threeWheelBean.getStartTimeStr() + "-" + threeWheelBean.getEndTimeStr() + ")");
                        startTime = threeWheelBean.getStartTimeInt();
                        endTime = threeWheelBean.getEndTimeLInt();
                       */
/* //刷新的时候将pageIndex始终为1
                        mPageIndex = 1;
                        mIsRefreshOrLoadMore = 0;
                        getVenueList();*//*

                       refreshData();
                    }

                    @Override
                    public void onNotTimeSelect() {

                    }
                });
                mChooseTimeShortDialog.show();
//            dateSelectPop.setData(childGrade, null);
                break;

            case R.id.area://区域分类
                SingleWheelDialog areaWheelDialog = new SingleWheelDialog(getActivity(), R.style.BottomToTopAnim);
                areaWheelDialog.setData("全部区域", mAreaStrLists);
                final ArrayList<HVSubCitiesBean> areaCopy = mAreasList;
                //地区筛选
                areaWheelDialog.setOnClickSubmitListener(new WheelDialog.OnClickSubmitListener() {
                    @Override
                    public void onClickSubmit(String[] values, ThreeWheelBean threeWheelBean) {

                        if (values != null && values.length == 1) {
                            String mTempAreaStr=values[0];
                            EventBus.getDefault().post(new UiEvent(EventConstant.FLAG_SEARCH_AREA,mTempAreaStr));
//                             //刷新的时候将pageIndex始终为1

                            // 统计各项点击次数
                            HashMap<String, String> map = new HashMap<>();
                            map.put("areaId", areaCode);
                            StatisticsManager.onEvent(mContext, StatisticsManager.VenueList_Area, map);

                            */
/*mPageIndex = 1;
                            mIsRefreshOrLoadMore = 0;
                            getVenueList();*//*

                            */
/*refreshData();*//*

                        }
                    }

                    @Override
                    public void onNotTimeSelect() {

                    }
                });
                areaWheelDialog.show();
                break;
        }

    }

    */
/**
     * 根据地区名称查询AreaCode
     * @param mTempAreaStr 地区名称
     *//*


    private void getAreaCode(String mTempAreaStr) {
        if ("全部区域".equals(mTempAreaStr)) {
            areaCode = citiesBean.getAreaid();
        } else {
            for (HVSubCitiesBean area : mAreasList) {
                if (mTempAreaStr.equals(area.getName())) {
                    areaCode = area.getAreaid();
                }
            }
        }
    }

    */
/**
     * 根据projectName获取ProjectId 将全部运动显示 所有运动
     * @param mTempProjectName 运动名称
     *//*


    private void getProjectId(String mTempProjectName) {
        if (mTempProjectName.equals(Constants.ALL_SPORT_STR)){//全部
            projectId=null;
            projectName=Constants.ALL_SPORT_STR;
            mProjectStr=Constants.ALL_SPORT;
        }else {
            projectName=mTempProjectName;
            mProjectStr=mTempProjectName;
        }
            //非全部去查询ProjectId
            for (HVProjectBean bean : hVProjectBean) {
                if (projectName.equals(bean.getProjectName())) {
                    projectId = bean.getProjectId();
                }
            }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void onUpdateClick() {
        mPageIndex = 1;
        mIsRefreshOrLoadMore = 0;
        mActivity.loadingView.show();
        getVenueList();
    }
    //Tab页切换 更新 项目 和区域
    @Subscribe
    public void setSearchContent(UiEvent mUiEvent){
        if(EventConstant.FLAG_SEARCH_PROJECT.equals(mUiEvent.getKey())){//运动分类更新
            String mProjectObj= (String) mUiEvent.getObject();//选中的运动字段  根据全部 来显示所有运动
           */
/* if(Constants.ALL_SPORT_STR.equals(mProjectObj)){//全部的时候 显示所有运动
                projectName=Constants.ALL_SPORT_STR;
            }else
            projectName=mProjectObj;*//*

            getProjectId(mProjectObj);
            tvGymsCategory.setText(mProjectStr);

            refreshData();//刷新数据
        }else if(EventConstant.FLAG_SEARCH_AREA.equals(mUiEvent.getKey())){//地区分类更新
            String mAreaObj= (String) mUiEvent.getObject();
            tvGymsArea.setText(mAreaObj);
            getAreaCode(mAreaObj);
            refreshData();//刷新数据
        }
    }

    */
/**
     * 筛选条件变更 刷新数据
     *//*


    private void refreshData() {
        //刷新的时候将pageIndex始终为1
        mPageIndex = 1;
        mIsRefreshOrLoadMore = 0;
        getVenueList();
    }
}
*/
